package org.example.controller;

import org.example.model.Book;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

//使用@RestController注解替换@Controller与@ResponseBody注解，简化书写
@RestController
@RequestMapping("/books")
public class BookController {

    /**
     * 简化操作类型操作
     */
    @PostMapping
    public String save(@RequestBody Book book) {
        System.out.println("book save..." + book);
        return "{'module':'book save'}";
    }

    @GetMapping
    public List<Book> update() {
        System.out.println("book getAll is running ...");
        List<Book> bookList = new ArrayList<Book>();
        Book book1 = new Book();
        book1.setName("SpringMVC入门教程");
        bookList.add(book1);
        Book book2 = new Book();
        book2.setName("SpringMVC实战教程");
        bookList.add(book2);
        Book book3 = new Book();
        book3.setName("SpringMVC实战教程进阶");
        bookList.add(book3);
        return bookList;
    }

}
